Aerospace Contrd and Application ›› 2025, Vol. 51 ›› Issue (1): 115-122.doi: 10.3969/j.issn.1674 1579.2025.01.012

Previous Articles    

Unit Test Generation for C Programs via Large Language Models

  

  • Online:2025-02-26 Published:2025-03-07

Abstract: Unit testing is used to verify the functionality of individual software modules, making it a crucial step in the software development process. It helps in identifying defects in the code in a timely manner, thereby improving the quality and reliability of the software. Manually writing unit tests is time consuming and labor intensive, often missing important code logic. To address this, researchers have proposed techniques for automatic generation of unit tests. Recently, pre trained large language models (LLM) have been widely applied to tasks related to code generation, and there has been work on generating unit tests for languages such as Java and JavaScript. However, in safety critical domains such as aerospace, C language programs are predominantly used. To fill this gap, we designed and implemented an LLM based multi agent interaction method for generating unit tests for C programs, named LLM4CUTCG. To verify the effectiveness of this method, we constructed 125 target programs without data leakage risks and generated tests for these programs. Experimental results show that the line coverage of the tests generated by LLM4CUTCG is 91.71%, and the assertion correctness rate is 50.05%. The coverage rate outperforms traditional methods such as symbolic execution and fuzz testing.

Key words: software testing, unit testing, test generation, code generation, large language model, test oracle

CLC Number: 

  • V44